package com.ruoyi.system.mapper.uploaddownload;

import com.ruoyi.system.domain.dto.TTestPointInfoDTO;
import com.ruoyi.system.domain.excle.GongLvCheExcel;
import com.ruoyi.system.domain.excle.GuoMinTiZhiChengRen;
import com.ruoyi.system.domain.excle.GuoMinTiZhiLaoRen;
import com.ruoyi.system.domain.excle.GuoMinTiZhiYouEr;
import com.ruoyi.system.domain.excle.TiChengFenExcel;
import com.ruoyi.system.domain.excle.XueYaJiExcel;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * 部门管理 数据层
 *
 * @author ruoyi
 */
@Mapper
public interface UploadMapper {

    // 获取机构信息
    @Select("SELECT a.*,a.is_check isCheck,a.is_check_retest isCheckRetest,a.booking_date bookingDate,a.booking_time bookingTime, b.dept_name name, b.organizationcode FROM t_testpoint a " +
            "LEFT JOIN sys_dept b ON a.org_id = b.dept_id WHERE YEAR = #{year} AND a.org_id = #{orgId} AND a.status = 1")
    TTestPointInfoDTO selectTTestPointInfoList(@Param("year") String year,@Param("orgId") Long orgId);

    // 无数据表时创建表
    @Update("create table if not exists ${newTableName} like ${oldTableName}")
    void createDataTable(@Param("newTableName")String newTableName,@Param("oldTableName") String oldTableName);

    // 更新校验gps并修改校验状态
    @Update("update t_testpoint set is_check=#{isCheck}, booking_date=#{bookingDate},booking_time=#{bookingTime} where id=#{testPointid}")
    int updateTestPointInfo(@Param("isCheck") String isCheck,@Param("bookingDate") String bookingDate,@Param("bookingTime") String bookingTime,@Param("testPointid") Long testPointid);

    @Select("SELECT COUNT(1) FROM `t_testpoint` WHERE org_id = #{deptId} AND year = YEAR(CURRENT_DATE) and status = 1")
    int existsTestPoint(@Param("deptId") Long deptId);

    @Select("SELECT a.*,a.is_check isCheck,a.is_check_retest isCheckRetest,a.booking_date bookingDate,a.booking_time bookingTime, b.dept_name name, b.organizationcode FROM t_testpoint a " +
            "LEFT JOIN sys_dept b ON a.org_id = b.dept_id WHERE a.token = #{token} and a.status = 1")
    TTestPointInfoDTO selectTTestPointInfoByToken(@Param("token") String token);

    List<Map<String, Object>> getQuestion(@Param("questionDesc") String questionDesc, @Param("questionStatus") String questionStatus,
                                          @Param("peopleAgeMin") Double peopleAgeMin,@Param("peopleAgeMax") Double peopleAgeMax);

    List<Map<String, Object>> getPaper(@Param("questionId") String questionId);

    List<Map<String, Object>> getDownloadQuestionData(Map<String, Object> paramMap);

    List<Map<String, Object>> getDownloadWhole(Map<String, Object> paramMap);

    List<GuoMinTiZhiYouEr> getDownloadDataYouEr(@Param("organizationCode") String organizationCode,@Param("projectTableName") String projectTableName,
                                                @Param("huiyuanxinxiTableName") String huiyuanxinxiTableName,@Param("starttime") String starttime,@Param("endtime") String endtime,
                                                @Param("peopleAgeMin") Double peopleAgeMin,@Param("peopleAgeMax") Double peopleAgeMax);

    List<GuoMinTiZhiChengRen> getDownloadDataChengRen(@Param("organizationCode") String organizationCode,@Param("projectTableName") String projectTableName,
                                                      @Param("huiyuanxinxiTableName") String huiyuanxinxiTableName,@Param("starttime") String starttime,@Param("endtime") String endtime,
                                                      @Param("peopleAgeMin") Double peopleAgeMin,@Param("peopleAgeMax") Double peopleAgeMax);

    List<GuoMinTiZhiLaoRen> getDownloadDataLaoRen(@Param("organizationCode") String organizationCode,@Param("projectTableName") String projectTableName,
                                                  @Param("huiyuanxinxiTableName") String huiyuanxinxiTableName,@Param("starttime") String starttime,@Param("endtime") String endtime,
                                                  @Param("peopleAgeMin") Double peopleAgeMin,@Param("peopleAgeMax") Double peopleAgeMax);

    List<XueYaJiExcel> getDownloadDataXueYaJi(@Param("organizationCode") String organizationCode,@Param("projectTableName") String projectTableName,
                                              @Param("huiyuanxinxiTableName") String huiyuanxinxiTableName,@Param("starttime") String starttime,@Param("endtime") String endtime,
                                              @Param("index") int index,@Param("rows") int rows);

    List<GongLvCheExcel> getDownloadDataGongLvChe(@Param("organizationCode") String organizationCode,@Param("projectTableName") String projectTableName,
                                                  @Param("huiyuanxinxiTableName") String huiyuanxinxiTableName,@Param("starttime") String starttime,@Param("endtime") String endtime,
                                                  @Param("index") int index,@Param("rows") int rows);

    List<TiChengFenExcel> getDownloadDataTiChengFen(@Param("organizationCode") String organizationCode,@Param("projectTableName") String projectTableName,
                                                    @Param("huiyuanxinxiTableName") String huiyuanxinxiTableName,@Param("starttime") String starttime,@Param("endtime") String endtime,
                                                    @Param("index") int index,@Param("rows") int rows);
}
